package com.zz.common.codeGenerator.dto;

import com.zz.common.base.dto.BaseDto;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.math.BigDecimal;
import java.util.Map;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * 代码生成业务表字段 实体类
 * @author zhang.lei
 * @since 2025-08-18 20:32:36
 */
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "代码生成业务表字段")
public class GenTableColumnDto extends BaseDto {

    @ApiModelProperty(value = "编号", name = "columnId")
    private String columnId;

    @ApiModelProperty(value = "归属表编号", name = "tableId")
    private String tableId;

    @ApiModelProperty(value = "列名称", name = "columnName")
    private String columnName;

    private Map<String, Object> columnShowNameNew;

    @ApiModelProperty(value = "列显示名称", name = "columnShowName")
    private String columnShowName;

    @ApiModelProperty(value = "列描述", name = "columnComment")
    private String columnComment;

    @ApiModelProperty(value = "列类型", name = "columnType")
    private String columnType;

    @ApiModelProperty(value = "JAVA类型", name = "javaType")
    private String javaType;

    @ApiModelProperty(value = "JAVA字段名", name = "javaField")
    private String javaField;

    @ApiModelProperty(value = "是否主键（1是）", name = "isPk")
    private String isPk;

    @ApiModelProperty(value = "是否自增（1是）", name = "isIncrement")
    private String isIncrement;

    @ApiModelProperty(value = "是否必填（1是）", name = "isRequired")
    private String isRequired;

    @ApiModelProperty(value = "是否为插入字段（1是）", name = "isInsert")
    private String isInsert;

    @ApiModelProperty(value = "是否编辑字段（1是）", name = "isEdit")
    private String isEdit;

    @ApiModelProperty(value = "是否列表字段（1是）", name = "isList")
    private String isList;

    @ApiModelProperty(value = "是否查询字段（1是）", name = "isQuery")
    private String isQuery;

    @ApiModelProperty(value = "是否为链接字段（1是）", name = "isLink")
    private String isLink;

    @ApiModelProperty(value = "是否为外键（1是）", name = "isFk")
    private String isFk;

    @ApiModelProperty(value = "查询方式（等于、不等于、大于、小于、范围）", name = "queryType")
    private String queryType;

    @ApiModelProperty(value = "显示类型（文本框、文本域、下拉框、复选框、单选框、日期控件）", name = "htmlType")
    private String htmlType;

    @ApiModelProperty(value = "字典类型", name = "dictType")
    private String dictType;

    @ApiModelProperty(value = "排序", name = "sort")
    private Integer sort;

    @ApiModelProperty(value = "创建者", name = "createBy", hidden = true)
    private String createBy;

    @ApiModelProperty(value = "创建时间", name = "createDate")
    private LocalDateTime createDate;

    @ApiModelProperty(value = "更新者", name = "updateBy", hidden = true)
    private String updateBy;

    @ApiModelProperty(value = "删除标识", name = "delFlag")
    private String delFlag;

    @ApiModelProperty(value = "更新时间", name = "updateDate")
    private LocalDateTime updateDate;

    // ================= 以下为自定义字段 =================
    public boolean isSuperColumn() {
        return isSuperColumn(this.javaField);
    }

    public static boolean isSuperColumn(String javaField) {
        return StringUtils.equalsAnyIgnoreCase(javaField,
                // BaseEntity
                "createBy", "createTime", "updateBy", "updateTime", "remark",
                // TreeEntity
                "parentName", "parentId", "orderNum", "ancestors");
    }

    public boolean isList() {
        return isList(this.isList);
    }

    public boolean isList(String isList) {
        return isList != null && StringUtils.equals("1", isList);
    }
}
